﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Linq;
using ALiteTeam.PackageTracer.Core;
using ALiteTeam.PackageTracer.Core.Impl;
using ALiteTeam.PackageTracer.Data;
using Microsoft.Phone.Tasks;
using Microsoft.Phone.Shell;
using ALiteTeam.PackageTracer.ViewModel;

namespace ALiteTeam.PackageTracer.View
{
    public partial class InputOrder : PhoneApplicationPage
    {
        private ApplicationBarIconButton _AppBarBtnBrowser;
        private ApplicationBarIconButton _AppBarBtnCall;

        public InputOrder()
        {
            InitializeComponent();

            this._AppBarBtnBrowser = new ApplicationBarIconButton(App.Current.GetIconUri(AppBarIcons.IE));
            this._AppBarBtnBrowser.Text = "访问官网";
            this._AppBarBtnBrowser.Click += new EventHandler(_AppBarBtnBrowser_Click);

            this._AppBarBtnCall = new ApplicationBarIconButton(App.Current.GetIconUri(AppBarIcons.Call));
            this._AppBarBtnCall.Text = "电话联系";
            this._AppBarBtnCall.Click += new EventHandler(_AppBarBtnCall_Click);

            ApplicationBar.Buttons.Add(_AppBarBtnBrowser);
            ApplicationBar.Buttons.Add(_AppBarBtnCall);
        }

        void _AppBarBtnCall_Click(object sender, EventArgs e)
        {
            var viewModel = this.DataContext as InputOrderViewModel;

            PhoneCallTask task = new PhoneCallTask();
            task.PhoneNumber = viewModel.PhoneNumber.Replace("-", string.Empty);
            task.DisplayName = viewModel.DisplayName;
            task.Show();
        }

        void _AppBarBtnBrowser_Click(object sender, EventArgs e)
        {
            var viewModel = this.DataContext as InputOrderViewModel;

            WebBrowserTask task = new WebBrowserTask();
            task.Uri = new Uri(viewModel.WebSite);
            task.Show();
        }
    }
}
